ABC285 D - Change Usernames
提出
code: python
from collections import deque
from collections import defaultdict
n = int(input())
changed = set()
d = defaultdict(str)
# どこかで循環があったらダメ
for s, t in st:
for k in list(d.keys()):
while q:
next = q.popleft()
if next in changed:
print("No")
exit()
changed.add(next)
if k not in changed:
print("Yes")
解答
code: python
from collections import defaultdict
n = int(input())
# print(st)
d = defaultdict(str)
start = []
for s, t in st:
start.append(s)
# print(d)
# {'aaa': 'bbb', 'yyy': 'zzz', 'ccc': 'ddd', 'xxx': 'yyy', 'bbb': 'ccc'}
# print(start)
visited = set()
for start_step in start:
# 既に調べたループが無くなるまで
while next_step not in visited:
visited.add(next_step)
if next_step == "":
break
# 更新
# 循環が発生している
if next_step == start_step:
print("No")
exit()
print("Yes")
テーマ
メモ
提出
code: python
from collections import defaultdict
from collections import deque
n = int(input())
# 循環
d = defaultdict(str)
visited = defaultdict(bool)
for s, t in st:
print(d)
# defaultdict(<class 'str'>, {'aaa': 'bbb', 'yyy': 'zzz', 'ccc': 'ddd', 'xxx': 'yyy', 'bbb': 'ccc'})
for k, v in d.items():
now = k
while True:
print("No")
exit()
if not next:
break
else: